<?php

function LoadOptions() {
    global $options;
	$name='options';
	if ( !cache_check($name) ) {
		$r=mysql_query('SELECT SQL_CACHE `name`,`value` FROM `options`;');
		while($option=mysql_fetch_row($r) ) {
			$options[$option[0]]=$option[1];
		}
		cache_write($name, $options,1000);
	} else $options=cache_read($name);
}

function SetOption($name,$value) {
    global $options;
	if ( !empty($options[$name]) ) {
		sql_query('UPDATE options SET `value` = '.sqlesc($value).' WHERE `name` = '.sqlesc($name) );
	} else {
		sql_query('INSERT INTO options ( `name`, `value` ) VALUES ( '.sqlesc($name).','.sqlesc($value).')' );
	}
    $options[$name]=$value;
	cache_unset('options');
}

function DelOption($name) {
    global $options;
    sql_query('DELETE FROM `options` WHERE name='.sqlesc($name).';');
    unset($options[$name]);
	cache_unset('options');
}

?>
